<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Display Images</title>
  <style>
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
      padding: 20px;
      display: flex;
      justify-content: center;
      background-color: #f8f8f8;
    }

    #images-container {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      justify-content: center;
      max-width: 1200px;
      width: 100%;
    }

    img {
      width: calc(33.33% - 20px); /* 33.33% for three images in a row with a 20px gap */
      max-width: 300px; /* Maximum width for larger screens */
      height: auto;
      border-radius: 10px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
      transition: transform 0.3s ease-in-out;
      cursor: pointer;
    }

    img:hover {
      transform: scale(1.05);
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    }

    @media (max-width: 768px) {
      img {
        width: calc(50% - 20px); /* 50% for two images in a row with a 20px gap on smaller screens */
      }
    }

    @media (max-width: 480px) {
      img {
        width: calc(100% - 20px); /* Full width for one image on smaller screens */
      }
    }

  </style>
</head>
<body>
    <div id="images-container"></div>
  
    <script>
      // Define variables for customization
      const repoOwner = 'TCNotRespond';
      const repoName = 'my-photographic-works';
      const imagesFolder = 'images';
  
      async function displayImages() {
        const apiUrl = `https://gitee.com/api/v5/repos/${repoOwner}/${repoName}/contents/${imagesFolder}?ref=master`;
        const response = await fetch(apiUrl);
        const data = await response.json();
  
        const imagesContainer = document.getElementById('images-container');
  
        data.forEach(async image => {
          const imageResponse = await fetch(image.url);
          const imageData = await imageResponse.json();
  
          const imageElement = document.createElement('img');
          imageElement.src = `data:image/jpeg;base64,${imageData.content}`;
          imageElement.alt = imageData.name;
          imageElement.addEventListener('click', () => downloadImage(imageElement.src, imageData.name));
          imagesContainer.appendChild(imageElement);
        });
      }
  
      function downloadImage(src, filename) {
        const link = document.createElement('a');
        link.href = src;
        link.download = filename;
        link.click();
      }
  
      displayImages();
    </script>
  </body>
</html>
